package io.renren.api;

import io.renren.entity.BookVideo;
import io.renren.entity.Count;
import io.renren.entity.vo.VideoInfo4MiniProject;
import io.renren.service.BookVideoService;
import io.renren.service.CountService;
import io.renren.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: hongyuliu
 * @Date: 2020-06-02
 * @Version 1.0
 */
@RestController
@RequestMapping("/mini/project/")
public class MiniProjectController {
    @Autowired
    private BookVideoService videoService;

    @Autowired
    private CountService countService;

    @GetMapping("/video/info/{id}")
    public R getVideoInfo(@PathVariable Long id){
        BookVideo bookVideo = videoService.queryObject(id);
        Count count = countService.queryObject(id);
        VideoInfo4MiniProject miniProject = VideoInfo4MiniProject.builder()
                .id(bookVideo.getId())
                .zan(count.getZan())
                .videoUrl(bookVideo.getVideoUrl())
                .viewNumber(count.getViewNumber())
                .unitName(bookVideo.getUnitName())
                .videoName(bookVideo.getVideoName())
                .bookName(bookVideo.getBook().getName())
                .pageNo(bookVideo.getPageNo().toString())
                .gradeName(bookVideo.getBook().getGrade().getName())
                .versionName(bookVideo.getBook().getVersion().getName())
                .seasonName(bookVideo.getBook().getSeason().getName())
                .subjectName(bookVideo.getBook().getSubject().getName())
                .fascicleName(bookVideo.getBook().getFascicle().getName())
                .build();

        return R.ok().put("videoInfo",miniProject);
    }
}
